<template>
  <div class="login-panel">
    <h1>后台管理系统</h1>
    <el-tabs type="border-card" class="tabs" stretch v-model="activeTab">
      <el-tab-pane name="userAccount">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><user /></el-icon>
            <span>账户登录</span>
          </span>
        </template>
        <login-account ref="accountRef"></login-account>
      </el-tab-pane>
      <el-tab-pane name="phoneAccount">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><cellphone /></el-icon>
            <span>手机号登录</span>
          </span>
        </template>
        <login-phone ref="phoneRef"></login-phone>
      </el-tab-pane>
    </el-tabs>
    <div class="helps">
      <el-checkbox label="记住密码" v-model="isSavePassword"></el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="loginHandler">点我登录</el-button>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { User, Cellphone } from '@element-plus/icons-vue'
import LoginAccount from '../LoginAccount/LoginAccount.vue'
import LoginPhone from '../LoginPhone/LoginPhone.vue'

export default defineComponent({
  name: 'LoginPanel',
  setup() {
    const isSavePassword = ref(false)
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const phoneRef = ref<InstanceType<typeof LoginPhone>>()
    const activeTab = ref('userAccount')
    const loginHandler = () => {
      if (activeTab.value === 'userAccount') {
        accountRef.value?.login(isSavePassword.value)
      } else if (activeTab.value === 'phoneAccount') {
        phoneRef.value?.login()
      }
    }
    return {
      isSavePassword,
      activeTab,
      accountRef,
      phoneRef,
      loginHandler
    }
  },
  components: {
    LoginAccount,
    LoginPhone,
    User,
    Cellphone
  }
})
</script>

<style scoped lang="less">
.login-panel {
  width: 360px;
  transform: translateY(-64%);
  .tabs .custom-tabs-label .el-icon {
    vertical-align: middle;
  }

  .tabs .custom-tabs-label span {
    vertical-align: middle;
    margin-left: 4px;
  }

  .helps {
    display: flex;
    margin-top: 6px;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
  }
}
</style>
